/**
 * 快速排序
 */

function quickSort(arr) {
    // 判断数组长度是否为0或者1
    if (arr.length === 1 || arr.length === 0) return arr
    let left = [], right = []
    let mid = arr[0]
    for (let i = 1; i < arr.length; i++) {
        if (arr[i] < mid) {
            left.push(arr[i])
        } else {
            right.push(arr[i])
        }
    }
    return [...quickSort(left), mid, ...quickSort(right)]
}

let arr = [1, 2, 1, 4, 77, 33, 44, 88]
console.log('quick', quickSort(arr))

//冒泡排序
function Bubble(arr) {
    let temp
    for (let i = 0; i < arr.length; i++) {
        for (let j = i + 1; j < arr.length; j++) {
            if (arr[j] < arr[i]) {
                temp = arr[1]
                arr[i] = arr[j]
                arr[j] = temp
            }
        }
    }
    return arr
}

console.log('bubble:', Bubble(arr))

